/*
 * @Description: 
 * @Author: DXV-RGWU-TUFH-RFCY-IEGMYY
 * @Date: 2021-07-03 11:41:05
 * @LastEditTime: 2023-08-01 17:29:23
 * @LastEditors: DXV-RGWU-TUFH-RFCY-IEGMYY
 */
export default {
  debounce (fn, delay = 300) { // 默认300毫秒
    let timer
    return function (...args) {
      if (timer) {
        clearTimeout(timer)
      }
      timer = setTimeout(() => {
        fn.apply(this, args) // this 指向vue
      }, delay)
    }
  },
  getProCurrentHref () {
    let _href = window.location.href
    let index = _href.indexOf('#')
    let newHref = _href.slice(0, index)
    newHref = window.lbConfig.isWe7 ? newHref + '&s=' : window.location.origin + '/index.php'
    return newHref
  },
  pick (obj, arr) {
    return arr.reduce((acc, curr) => {
      if (curr in obj) {
        acc[curr] = obj[curr]
      }
      return acc
    }, {})
  },
  getItems (o, type = 'id', sign = ',') {
    let items = []
    o = o || []
    o.forEach((item) => {
      items.push(item[type])
    })
    return items.join(sign)
  },
  randomWord (randomFlag, min, max) {
    let str = ''
    let range = min
    let arr = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z']
    // 随机产生
    if (randomFlag) {
      range = Math.round(Math.random() * (max - min)) + min
    }
    for (var i = 0; i < range; i++) {
      let pos = Math.round(Math.random() * (arr.length - 1))
      str += arr[pos]
    }
    return str
  }
}
